<%@ page import="com.example.ending_demo.dao.UserDao" %>
<%@ page import="com.example.ending_demo.model.User" %>
<%--
  Created by IntelliJ IDEA.
  User: ASUS
  Date: 2023/12/6
  Time: 21:54
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<div class="header">
    <nav class="navbar navbar-set">
        <div class="container-fluid">
            <!-- Brand and toggle get grouped for better mobile display -->
            <div class="navbar-header">
                <button type="button" class="navbar-toggle collapsed" data-toggle="collapse"
                        data-target="#bs-example-navbar-collapse-1" aria-expanded="false">
                    <span class="sr-only">Toggle navigation</span>
                    <span class="icon-bar"></span>
                    <span class="icon-bar"></span>
                    <span class="icon-bar"></span>
                </button>
                <a class="navbar-brand" href="#">通讯录</a>
            </div>

            <!-- Collect the nav links, forms, and other content for toggling -->
            <div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
                <ul class="nav navbar-nav">
                    <li><a href="index.jsp">首页</a></li>
                    <%
                        User user = new User();
                        user = (User) session.getAttribute("user");
                        if (user!=null){
                    %>
                    <li><a href="${pageContext.servletContext.contextPath}/address_add.jsp">新增通讯录</a></li>
                    <li><a href="AddressListPageServlet">管理通讯录</a></li>
                    <%
                        }
                    %>
                </ul>
                    <%
                        if(user!=null){
                    %>
                <form class="navbar-form navbar-left" action="SearchAddressServlet">
                    <div class="form-group">
                        <input type="text" class="form-control" name="search" placeholder="搜索">
                    </div>
                    <button type="submit" class="btn btn-default">查询</button>
                </form>
                    <%
                        }
                    %>
                <ul class="nav navbar-nav navbar-right">
                    <%

                        if(user==null){

                    %>
                    <li><a href="${pageContext.servletContext.contextPath}/register.jsp">注册</a></li>
                    <li class="active"><a href="LoginServlet">登录</a></li>
                    <%
                    }else {
                    %>


                            <li><a href="#">用户名:<%=user.getUsername()%></a></li>
                            <li><a href="#">个人中心</a></li>
                            <li><a href="LogoutServlet">退出</a></li>
<%--                            <%session.invalidate();--%>
<%--                            %>--%>


                    <%
                        }
                    %>
                </ul>
            </div><!-- /.navbar-collapse -->
        </div><!-- /.container-fluid -->
    </nav>
</div>

